package com.xmall.search.handler.config;

import com.xmall.listener.IConfigChangeHandler;
import com.xmall.search.define.constants.SearchConstants;
import com.xmall.timer.manager.TimerTaskManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Properties;

/**
 * 定时任务配置变化处理器
 */
@Slf4j
@Component
public class TimerTaskConfigChangeHandler implements IConfigChangeHandler {

    @Resource
    private TimerTaskManager timerTaskManager;

    @Override
    public void handle(Properties properties) {
        try {
            this.compareCronAndRestartTask(timerTaskManager, SearchConstants.TimerTask.PRODUCT_DELETE_LOG_RETRY_TASK, properties.getProperty("productDeleteLogRetryCron"));
            this.compareCronAndRestartTask(timerTaskManager, SearchConstants.TimerTask.PRODUCT_UPDATE_LOG_RETRY_TASK, properties.getProperty("productUpdateLogRetryCron"));
        }catch (Exception e) {
            log.error("TimerTaskConfigChangeHandler error: {}", e.getMessage());
        }
    }

}
